package com.xy.xymall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author XY
 * @version 1.0
 * @date 2020/11/25 12:39
 * @Description 订单确认页需要用到的数据
 */
public class OrderConfirmVo {

    //收获地址
    @Getter @Setter
    List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter @Setter
    List<OrderItemVo> items;

    //积分
    @Getter @Setter
    Integer integration;

    //订单令牌,放重复提交
    @Getter @Setter
    String orderToken;

    @Getter @Setter
    Map<Long, Boolean> stocks;

    public Integer getCount(){
        Integer i = 0;
        if(items!=null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    //订单总额
    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum=new BigDecimal(0);
        if(items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付价格
    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
